package action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class UploadAction extends ActionSupport {
	private List<File> upload;
	private List<String> uploadFileName;
	private List<String> uploadContentType;

	public String doUpload() throws Exception {
		System.out.println(upload.get(0));
		for (int i = 0; i < upload.size(); i++) {
			String savePath = ServletActionContext.getServletContext()
					.getRealPath("/upload/" + this.uploadFileName.get(i));
			System.out.println(savePath);
			FileInputStream fis = new FileInputStream(upload.get(i));
			FileOutputStream fos = new FileOutputStream(savePath);
			IOUtils.copy(fis, fos);
			fos.flush();
			fos.close();
			fis.close();
		}

		return SUCCESS;
	}

	/**
	 * 获取 upload
	 * 
	 * @return upload
	 */
	public List<File> getUpload() {
		return upload;
	}

	/**
	 * 设置 upload
	 * 
	 * @param upload
	 *            upload
	 */
	public void setUpload(List<File> upload) {
		this.upload = upload;
	}

	/**
	 * 获取 uploadFileName
	 * 
	 * @return uploadFileName
	 */
	public List<String> getUploadFileName() {
		return uploadFileName;
	}

	/**
	 * 设置 uploadFileName
	 * 
	 * @param uploadFileName
	 *            uploadFileName
	 */
	public void setUploadFileName(List<String> uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	/**
	 * 获取 uploadContentType
	 * 
	 * @return uploadContentType
	 */
	public List<String> getUploadContentType() {
		return uploadContentType;
	}

	/**
	 * 设置 uploadContentType
	 * 
	 * @param uploadContentType
	 *            uploadContentType
	 */
	public void setUploadContentType(List<String> uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

}
